//
//  NSDate+help.m
//  VideoExam
//
//  Created by apple on 2020/6/15.
//

#import "NSDate+help.h"

@implementation NSDate (help)

/// 获取这个时间几天以后的时间
/// @param days 几天
/// @param date_str 时间字符串
+ (NSDate *)get_A_few_days_later_days:(NSInteger)days date_str:(NSString *)date_str {
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date=[dateFormatter dateFromString:date_str];
    
    NSTimeInterval oneDay = 24*60*60*1;  // 一天一共有多少秒
    //根据一个时间 返回多少秒以后的时间
    NSDate *appointDate = [[NSDate alloc] initWithTimeInterval:oneDay * days sinceDate:date];
    return appointDate;
}

/// 获取两个时间的时间差 date1 小的时间 date2 大的时间  返回时间差字符串
/// @param date1 小的时间
/// @param date2 大的时间
+ (NSString *)get_Time_difference_date1:(NSDate *)date1 date2:(NSDate *)date2 {
    NSTimeInterval value= [date2 timeIntervalSinceDate:date1];
    NSInteger seconds = (NSInteger)value;
    NSInteger d = seconds/ 60 / 60 / 24;//天数
    NSInteger h = seconds  / 60 / 60 % 24;//小时
    NSInteger  m = seconds  / 60 % 60;//分钟
    NSInteger  s = seconds  % 60;//秒
    NSLog(@"%ld天 %ld小时 %ld分 %ld秒",d,h,m,s);
    NSString * dateStr = [NSString stringWithFormat:@"%ld天%ld小时 %ld分后自动关闭",d,h,m];
    return dateStr;
}

/// 获取当前本地时间
+ (NSDate *)get_localDate {
    NSDate *date = [NSDate date];
    
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    
    NSInteger interval = [zone secondsFromGMTForDate: date];
    
    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];
    
    return localeDate;
}


@end
